<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\livebroadcast\model;

use app\cassification\model\ClassificationDictionary;
use plugin\saiadmin\basic\BaseNormalModel;

/**
 * 厂播列表表模型
 */
class liveBroadcast extends BaseNormalModel
{

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'broadcast_id';

    /**
     * 数据库表名称
     * @var string
     */
    protected $table = 'eb_live_broadcast';

    protected $append = ['broadcast_type_text','cate_text'];
    
    /**
     * 标题 搜索
     */
    public function searchBroadcastTitleAttr($query, $value)
    {
        $query->where('broadcast_title', 'like', '%'.$value.'%');
    }
    
    /**
     * 企业名称 搜索
     */
    public function searchEnterpriseNameAttr($query, $value)
    {
        $query->where('enterprise_name', 'like', '%'.$value.'%');
    }


    public function getBroadcastTypeTextAttr($value,$data)
    {
        if(isset($data['broadcast_type'])){
            return    ClassificationDictionary::where('dictionary_id', $data['broadcast_type'])->value('classification_name_zh');
        }
        return '';
    }

    public function getCateTextAttr($value,$data)
    {
        if(isset($data['cate'])){
            return    ClassificationDictionary::where('dictionary_id', $data['cate'])->value('classification_name_zh');
        }
        return '';
    }
}
